package cn.wizzer.app.web.modules.controllers.user;


import cn.wizzer.app.user.modules.services.GroupLogService;
import cn.wizzer.app.user.modules.services.GroupMemberService;
import cn.wizzer.app.user.modules.services.UserChatMsgService;
import cn.wizzer.app.web.commons.filter.ApiTokenFilter;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;

/**
 * 用户未读聊天消息数量(群聊、客服)
 *
 * @author .
 */
@IocBean
@At("/api/user/unreadChat")
public class ApiUserUnreadChat {
    @Inject
    @Reference
    private GroupLogService groupLogService;

    @Inject
    @Reference
    private UserChatMsgService chatMsgService;

    /**
     * 群聊未读消息数量
     *
     * @return Object
     */
    @At("/groupNum")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Object groupUnreadNum() {
        String appid = Mvcs.getReq().getHeader("appid");
        return Result.success().addData(groupLogService.groupReadFlag(appid));
    }


    /**
     * 客服未读消息数量
     *
     * @return Object
     */
    @At("/attendantNum")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Object attendantUnreadNum() {
        String appid = Mvcs.getReq().getHeader("appid");
        return Result.success().addData(chatMsgService.attendantUnreadNum(appid));
    }

}
